package com.zr.task.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zr.common.annotation.Log;
import com.zr.common.core.controller.BaseController;
import com.zr.common.core.domain.AjaxResult;
import com.zr.common.enums.BusinessType;
import com.zr.task.domain.EimTaskLog;
import com.zr.task.service.IEimTaskLogService;
import com.zr.common.utils.poi.ExcelUtil;
import com.zr.common.core.page.TableDataInfo;

/**
 * 任务日志Controller
 * 
 * @author zhaojie
 * @date 2022-10-21
 */
@RestController
@RequestMapping("/eim/log")
public class EimTaskLogController extends BaseController
{
    @Autowired
    private IEimTaskLogService eimTaskLogService;

    /**
     * 查询任务日志列表
     */
    @PreAuthorize("@ss.hasPermi('eim:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(EimTaskLog eimTaskLog)
    {
        startPage();
        List<EimTaskLog> list = eimTaskLogService.selectEimTaskLogList(eimTaskLog);
        return getDataTable(list);
    }

    /**
     * 导出任务日志列表
     */
    @PreAuthorize("@ss.hasPermi('eim:log:export')")
    @Log(title = "任务日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EimTaskLog eimTaskLog)
    {
        List<EimTaskLog> list = eimTaskLogService.selectEimTaskLogList(eimTaskLog);
        ExcelUtil<EimTaskLog> util = new ExcelUtil<EimTaskLog>(EimTaskLog.class);
        util.exportExcel(response, list, "任务日志数据");
    }

    /**
     * 获取任务日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('eim:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(eimTaskLogService.selectEimTaskLogById(id));
    }

    /**
     * 新增任务日志
     */
    @PreAuthorize("@ss.hasPermi('eim:log:add')")
    @Log(title = "任务日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EimTaskLog eimTaskLog)
    {
        return toAjax(eimTaskLogService.insertEimTaskLog(eimTaskLog));
    }

    /**
     * 修改任务日志
     */
    @PreAuthorize("@ss.hasPermi('eim:log:edit')")
    @Log(title = "任务日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EimTaskLog eimTaskLog)
    {
        return toAjax(eimTaskLogService.updateEimTaskLog(eimTaskLog));
    }

    /**
     * 删除任务日志
     */
    @PreAuthorize("@ss.hasPermi('eim:log:remove')")
    @Log(title = "任务日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eimTaskLogService.deleteEimTaskLogByIds(ids));
    }

    /**
     * 查询近七日总工时
     * 需求模块：数据大屏
     */
    @PreAuthorize("@ss.hasPermi('eim:log:query')")
    @PostMapping ("/selectAllCurrentEimTaskLog")
    public AjaxResult selectAllCurrentEimTaskLogo()
    {
        return AjaxResult.success(eimTaskLogService.selectAllCurrentEimTaskLog());
    }

    /**
     * 新增任务日志
     * 需求模块：APP
     */
    @PostMapping("/add")
    public AjaxResult addLog(EimTaskLog eimTaskLog)
    {
        return toAjax(eimTaskLogService.insertEimTaskLog(eimTaskLog));
    }
    /**
     * 根据任务ID查询任务日志
     * 需求模块：APP
     */
    @GetMapping(value = "/taskInfo/{id}")
    public TableDataInfo getInfoByTaskId(@PathVariable("id") Long id)
    {
        List<EimTaskLog> list=eimTaskLogService.selectEimTaskLogByTaskId(id);
        System.out.println(list);
        return getDataTable(list);
    }

}
